package com.fyzk.activity.lottery.basketball.fragment;

import android.os.Bundle;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.fyzk.base.BaseFragment;
import com.fyzk.activity.lottery.basketball.JCLQFragmentActivityI;
import com.fyzk.adapter.TabPageIndicatorAdapter;
import com.tyjc.lottery.R;
import com.viewpagerindicator.TabPageIndicator;

public abstract class JCLQTabBaseFragment extends BaseFragment {

	public TabPageIndicator tabIndicator;

	FragmentPagerAdapter fAdapter;
	private String[] titles = new String[] { "过关投注", "单关投注" };

	private ViewPager shop_detail_pager;

	BasketballWFBaseFragment[] fList;

	BasketballWFBaseFragment guoGuanFragment, danGuanFragment;

	public BasketballWFBaseFragment curFragment = null;// 当前fragment

	JCLQFragmentActivityI activity;

	public final int GUOGUAN = 0;
	public final int DANGUAN = 1;


	View mainView;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		mainView = inflater.inflate(R.layout.jclq_wf, null);
		activity = (JCLQFragmentActivityI) getActivity();
		initFragment();
		shop_detail_pager = mainView.findViewById(R.id.shop_detail_pager);
		tabIndicator = mainView.findViewById(R.id.shop_detail_indicator);
		initWFFragment();
		curFragment = guoGuanFragment;
		fAdapter = new TabPageIndicatorAdapter(this.getChildFragmentManager(),
				fList, titles);
		shop_detail_pager.setAdapter(fAdapter);
		shop_detail_pager.setOffscreenPageLimit(fList.length-1);//缓存剩余的fragment
		tabIndicator.setViewPager(shop_detail_pager);
		tabIndicator.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int position) {
				// TODO Auto-generated method stub
				if (position == GUOGUAN) {
					curFragment = guoGuanFragment;
				} else {
					curFragment = danGuanFragment;
				}
				curFragment.notifyList();
				activity.onBetChecked();
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub

			}
		});
		shop_detail_pager.setCurrentItem(0);
		return mainView;
	}
	
	public void initWFFragment(){
		fList = new BasketballWFBaseFragment[2];
		fList[0] = guoGuanFragment;
		fList[1] = danGuanFragment;
		curFragment = guoGuanFragment;
	}

	/** 初始化玩法的fragment */
	abstract void initFragment();
	
	
	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

}
